﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecreate.Popedom;
namespace Ecreate.Web.popedom.groupManage
{
    public partial class groupList : System.Web.UI.Page
    {

        Ecreate.Popedom.Service.IMenuService menuService = new Ecreate.Popedom.Service.SpringImpl.MenuServiceImpl();
        Ecreate.Popedom.Service.IGroupService groupService = new Ecreate.Popedom.Service.SpringImpl.GroupServiceImpl();
        GridHelper helper = new GridHelper();
        protected void Page_Load(object sender, EventArgs e)
        {
            helper.DeleteHandler = new EventHandler(LinkButton_DataBinding);
            helper.CrudUrl = "/popedom/groupManage/groupCrud.aspx";
            helper.setGridColumn(this.GridView1, "Id,groupName", "主键,组名称");
            this.GridView1.AutoGenerateColumns = false;
            this.GridView1.DataSource = groupService.getAll();
            this.GridView1.DataBind();
        }
        private void LinkButton_DataBinding(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            GridViewRow container = (GridViewRow)lb.NamingContainer;
            Ecreate.Popedom.tGroup group = (Ecreate.Popedom.tGroup)container.DataItem;
            lb.Text = helper.getDeleteFormatUrl();
            if (group.Adminflag == 1)
            {
                lb.Text = string.Format(lb.Text, group.Id, " return deleteHandler();");
            }
            else
            {
                lb.Text = string.Format(lb.Text, group.Id, "");
            }
            if (group.Users.Count > 0)
            {
                lb.Text = string.Format(lb.Text, group.Id, " return deleteUserHandler();");

            }
        }
    }
}
